#define _XOPEN_SOURCE  600
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

int main()
{
    char rx = 0;
    int master = 0;
    int c = 0;
    
    master = posix_openpt(O_RDWR); // gnome-terminal
    
    if( master > 0 ) {
        grantpt(master);
        unlockpt(master);
        
        printf("Slave: %s\n", ptsname(master));
        
        // 主设备读从设备的信息
        while( (c = read(master, &rx, 1)) == 1 ) {
            if( rx != '\r' ) {
                printf("%c", rx);
            }
        }
        
        close(master);
    } else {
        printf("create pty error...\n");
    }
    
    return 0;
}

